package com.bear.hospital.service.login.impl;

import com.bear.hospital.entity.LoginInfo;
import com.bear.hospital.mapper.LoginMapper;
import com.bear.hospital.pojo.Admin;
import com.bear.hospital.pojo.LoginMap;
import com.bear.hospital.service.admin.AdminService;
import com.bear.hospital.service.login.LoginService;
import com.bear.hospital.service.login.handle.LoginFactory;
import com.bear.hospital.service.login.handle.LoginStrategy;
import com.bear.hospital.service.minio.MinioService;
import com.bear.hospital.utils.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @Author： zmwx
 * @Date： 2025/1/23 15:53
 * @Describe：
 */
@Service
@Slf4j
public class LoginServiceImpl implements LoginService {
    @Resource
    private LoginMapper loginMapper;
    @Resource
    AdminService adminService;
    @Resource
    LoginFactory loginFactory;
    @Resource
    private MinioService MinioService;
    @Override
    public ResponseData AutoIdentityLogin(LoginInfo loginInfo) {
        List<LoginMap> loginMapList = loginMapper.selectByUsername(loginInfo.getUserName());
        if (loginMapList.isEmpty()) {
            return new ResponseData(500, "用户名不存在", new HashMap<>());
        }
        LoginMap loginMap = loginMapList.get(0);
        loginMap.setPassword(loginInfo.getPassword());
        return loginFactory.getLoginStrategy(loginMap.getIdentity()).login(loginMap);
    }

    @Override
    public ResponseData uploadSetProfilePhoto(MultipartFile file) {
      String imageUrl =  MinioService.uploadImage("hospital", file);
      if (imageUrl == null) {
          return ResponseData.fail("上传失败");
      }

        return ResponseData.success("上传成功", imageUrl);
    }
}
